<template>
  <div class="avue-top">
    <div class="top-bar__left">
      <div :class="[{ 'avue-breadcrumb--active': isCollapse }]"
           class="avue-breadcrumb"
           v-if="showCollapse">
        <i @click="setCollapse"
           class="icon-navicon"></i>
      </div>
    </div>
    <div class="top-bar__title">
      <div class="top-bar__item top-bar__item--show"
           v-if="showMenu">
        <top-menu ref="topMenu"></top-menu>
      </div>
      <span class="top-bar__item"
            v-if="showSearch">
        <top-search></top-search>
      </span>
    </div>
    <div class="top-bar__right">
      <el-tooltip content="服务平台"
                  effect="dark"
                  placement="bottom"
                  v-if="showColor">
        <div class="top-bar__item">
          <div @click="platform"
               style="cursor:pointer;;position: absolute;top: 50%;left: 50%;transform: translate(-90%, -50%) ;border: 1px solid #409eff; height: 24px; line-height: 24px; border-radius: 30px;font-size: 15px;padding: 0 10px;">
            服务平台
          </div>
        </div>
      </el-tooltip>
      <el-tooltip :content="$t('navbar.color')"
                  effect="dark"
                  placement="bottom"
                  v-if="showColor">
        <div class="top-bar__item">
          <top-color></top-color>
        </div>
      </el-tooltip>
      <!--      <el-tooltip :content="logsFlag?$t('navbar.bug'):logsLen+$t('navbar.bugs')"-->
      <!--                  effect="dark"-->
      <!--                  placement="bottom"-->
      <!--                  v-if="showDebug">-->
      <!--        <div class="top-bar__item">-->
      <!--          <top-logs></top-logs>-->
      <!--        </div>-->
      <!--      </el-tooltip>-->
      <el-tooltip :content="$t('navbar.lock')"
                  effect="dark"
                  placement="bottom"
                  v-if="showLock">
        <div class="top-bar__item">
          <top-lock></top-lock>
        </div>
      </el-tooltip>
      <el-tooltip :content="$t('navbar.theme')"
                  effect="dark"
                  placement="bottom"
                  v-if="showTheme">
        <div class="top-bar__item top-bar__item--show">
          <top-theme></top-theme>
        </div>
      </el-tooltip>
      <!--      <el-tooltip :content="$t('navbar.notice')"-->
      <!--                  effect="dark"-->
      <!--                  placement="bottom">-->
      <!--        <div class="top-bar__item top-bar__item&#45;&#45;show">-->
      <!--          <top-notice></top-notice>-->
      <!--        </div>-->
      <!--      </el-tooltip>-->
      <!--      <el-tooltip :content="$t('navbar.language')"-->
      <!--                  effect="dark"-->
      <!--                  placement="bottom">-->
      <!--        <div class="top-bar__item top-bar__item&#45;&#45;show">-->
      <!--          <top-lang></top-lang>-->
      <!--        </div>-->
      <!--      </el-tooltip>-->
      <el-tooltip :content="isFullScren?$t('navbar.screenfullF'):$t('navbar.screenfull')"
                  effect="dark"
                  placement="bottom"
                  v-if="showFullScren">
        <div class="top-bar__item">
          <i :class="isFullScren?'icon-tuichuquanping':'icon-quanping'"
             @click="handleScreen"></i>
        </div>
      </el-tooltip>
      <img src="~@/assets/img/avatar.png"
           class="top-bar__img" alt="">
      <el-dropdown>
        <span class="el-dropdown-link">
          {{ userInfo.userName }}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>
            <router-link to="/">{{ $t('navbar.dashboard') }}</router-link>
          </el-dropdown-item>
          <el-dropdown-item>
            <router-link to="/info/index">{{ $t('navbar.userinfo') }}</router-link>
          </el-dropdown-item>
          <el-dropdown-item @click.native="logout"
                            divided>{{ $t('navbar.logOut') }}
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
import {mapGetters, mapState} from "vuex";
import {fullscreenToggel, listenfullscreen} from "@/util/util";
import topLock from "./top-lock";
import topMenu from "./top-menu";
import topSearch from "./top-search";
import topTheme from "./top-theme";
import topLogs from "./top-logs";
import topColor from "./top-color";
import topNotice from './top-notice'
import topLang from "./top-lang";
import {backHome, LoginOut} from "@/api/user";

export default {
  components: {
    topLock,
    topMenu,
    topSearch,
    topTheme,
    topLogs,
    topColor,
    topNotice,
    topLang
  },
  name: "top",
  data() {
    return {};
  },
  filters: {},
  mounted() {
    listenfullscreen(this.setScreen);
  },
  computed: {
    ...mapState({
      showDebug: state => state.common.showDebug,
      showTheme: state => state.common.showTheme,
      showLock: state => state.common.showLock,
      showFullScren: state => state.common.showFullScren,
      showCollapse: state => state.common.showCollapse,
      showSearch: state => state.common.showSearch,
      showMenu: state => state.common.showMenu,
      showColor: state => state.common.showColor
    }),
    ...mapGetters([
      "userInfo",
      "isFullScren",
      "tagWel",
      "tagList",
      "isCollapse",
      "tag",
      "logsLen",
      "logsFlag"
    ])
  },
  methods: {
    platform() {
      backHome()
    },
    handleScreen() {
      fullscreenToggel();
    },
    setCollapse() {
      this.$store.commit("SET_COLLAPSE");
    },
    setScreen() {
      this.$store.commit("SET_FULLSCREN");
    },
    logout() {
      this.$confirm(this.$t("logoutTip"), this.$t("tip"), {
        confirmButtonText: this.$t("submitText"),
        cancelButtonText: this.$t("cancelText"),
        type: "warning"
      }).then(() => {
        this.$store.dispatch("LogOut").then(() => {
          LoginOut()
        });
      });
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
